package com.dm.learn.java.validate;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataValidation {
	/**
	 * 判断是否为空
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isEmpty(String str) {
		if (str == null || str.equals("")) {
			return true;
		}
		return false;
	}

	/**
	 * 是否是一个email
	 * 
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email) {
		if (isEmpty(email)) {
			return false;
		}
		// 电子邮件
		String check = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";
		Pattern regex = Pattern.compile(check);
		Matcher matcher = regex.matcher(email);
		return matcher.matches();
	}
	/**
	 * 测试
	 * @param args
	 */
	public static void main(String[] args){
		System.out.println(isEmail("hcjhuanghe@qq.com"));
	}
}
